#!/usr/bin/env python3
import serial
import sys
import struct
import time

hr = float(sys.argv[1])
spo2 = float(sys.argv[2])

port = "5212"
ipaddress = "101.43.106.219"

ser = serial.Serial("/dev/ttyUSB0", 115200, 8, 'N', 1)
data = struct.pack(">dd", hr, spo2)

cmds = [
    "AT+MIPOPEN=1,,\"{}\",{},0\r".format(ipaddress, port),
    "AT+MIPSEND=1,\"{}\"\r".format(data.hex()),
    "AT+MIPPUSH=1\r",
    "AT+MIPCLOSE=1\r"
]

for cmd in cmds:
    ser.write(cmd.encode())
    time.sleep(0.1)